from DataManagement.models import DataCenterModel
from gxdm.models import *
from DataCenter.code import Code
from gxjg.models import Gxjg0101
from django.db import models


class Gxjg0301(DataCenterModel):
    class Meta(DataCenterModel.Meta):
        db_table = 'gxjg0301'
        verbose_name = 'GXJG0301 教职工党政职务表'
        verbose_name_plural = 'GXJG0301 教职工党政职务表'

    # xgh = models.CharField('学工号', max_length=64)
    teacher = models.ForeignKey(Gxjg0101, to_field='gh', on_delete=models.PROTECT, db_column='xgh', verbose_name='学工号')
    zwmc = models.CharField('职务名称', max_length=60)
    zwmcm = models.CharField('职务名称码', max_length=4, blank=True, null=True)
    zwlbm = models.CharField('职务类别码', max_length=2, choices=Code.ZWLB_CHOICE)
    zwflm = models.CharField('职务分类码', max_length=4, blank=True, null=True)
    zwjbm = models.CharField('职务级别码', max_length=2, blank=True, null=True, default='02')
    rzrq = models.DateField('任职日期', blank=True, null=True)
    # rzbm = models.CharField('任职部门', max_length=5, choices=Code.DEPARTMENT_CHOICE,)
    rzbm = models.ForeignKey(Dwbmdm, to_field='value', on_delete=models.PROTECT, db_column='rzbm', verbose_name='任职部门')
    rzks = models.CharField('任职科室', max_length=64, blank=True, null=True)
    rzfsm = models.CharField('任职方式码', max_length=1, blank=True, null=True)
    rzyy = models.CharField('任职原因', max_length=80, blank=True, null=True)
    rzwh = models.CharField('任职文号', max_length=24, blank=True, null=True)
    rzpzdw = models.CharField('任职批准单位', max_length=5, blank=True, null=True)
    zwbdlbm = models.CharField('职务变动类别码', max_length=1, blank=True, null=True)

    DQRZZT_CHOICE = (('1', '不在任'), ('2', '在任'))
    dqrzzt = models.CharField('当前任职状态', max_length=1, choices=DQRZZT_CHOICE, default='2')
    zwpx = models.CharField('职务排序', max_length=2, blank=True, null=True)
    zghcsdgz = models.CharField('主管或从事的工作', max_length=40, blank=True, null=True)
    mzrq = models.DateField('免职日期', blank=True, null=True)
    mzfsm = models.CharField('免职方式码', max_length=1, blank=True, null=True)
    mzyym = models.CharField('免职原因码', max_length=2, blank=True, null=True)
    mzwh = models.CharField('免职文号', max_length=24, blank=True, null=True)
    mzpzdw = models.CharField('免职批准单位', max_length=5, blank=True, null=True)

    def __str__(self):
        rzbm = self.rzbm.label if self.rzbm.label else ''
        rzks = self.rzks if self.rzks else ''
        zwmc = self.zwmc if self.zwmc else ''
        return ''.join([rzbm, rzks, zwmc])
